<?php
defined('BY_JYA') or exit('error');
/*
	创建拍卖订单
	参考源文件： \Application\Play\Controller\AuctionController.class.php 
*/

list($pid)=$arguments;
	$data = pdo_get('jy_jdpm_auction',array('id' => $pid));
    $margin = pdo_getcolumn('jy_jdpm_freezelog',array('pid' => $pid,'mid' => $data['mid'],'status' => 0),'pledge');
    $Goods  = pdo_get('jy_jdpm_goods',array('id' => $data['goodsid']));
	$goodsinfo=get_goodsinfo($pid);
	$Goods=array_merge($Goods,$goodsinfo);
        //平台佣金为起拍价2%
        $brokerage = $data['onset'] * 0.02;
        $OrderAllocation = plugin_set2('order');
        //获取商品信息
        $OrderInfo = [
            'ordersn'     => get_ordersn('jy_weishop_order','ordersn'),//订单号
            'type'         => 0 ,//订单类型  0竞拍 1 竞价 2一口价
            'mid'          => $data['mid'] ,//用户id
            'merchid'     => $Goods['merchid'] ,//卖家uid
            'price'        => $data['nowprice'] ,//商品价
            'createtime'   => TIMESTAMP,//订单生成时间
			'plugin_name'=>'jy_jdpm',
			'uniacid'=>$_SESSION['uniacid'],
            'status'       => 0 ,//支付状态0：待支付1：已支付待发货 2：已发货待收货3：已收货待评价 4：已评价卖家 5：申请退货 6：同意退货 7：不同意退货 8：买家已发货 9：卖家确认收货 10：已完成
        ];
		$OrderInfo2 = [
            'type'         => 0 ,//订单类型  0竞拍 1 竞价 2一口价
            'pid'          => $pid ,//$data['goodsid'] ,//拍卖表ID
            'commission'   => $brokerage ,//手续费 按起拍价固定2%
            'service_fees' => $data['nowprice'] / 100 ,//服务费 成交价服务费1%
            'broker'       => $brokerage ,//佣金
            'broker_buy'   => $brokerage ,//买家需要支付的佣金
            'margin'       => $margin ,//保证金
			'status'      => 0,
			'mid'      => $data['mid'],
			'uniacid'=>$data['uniacid'],
        ];
        //写入订单表
		pdo_insert('jy_weishop_order',$OrderInfo);
		$orderid = pdo_insertid();
		$OrderInfo2['orderid']=$orderid;
		pdo_insert('jy_jdpm_order',$OrderInfo2);
		pdo_update('jy_jdpm_auction',array('endstatus' => -1),array('id' => $pid));
		//发送短信通知成功竞拍者
		$member=get_member($data['mid']);
		$content=array(
			'username'=>$member['nickname'],
			'pname'=>$Goods['title'],
		);
		$this->model('notice')->set_sms($member['mobile'],$content,2);
		$message='恭喜您已成功获拍，请于竞拍结束24小时之内一次性付清拍品货款。若逾期未付款，导致系统自动关闭交易，将承担违约责任。竞拍保证金将按比例赔付给平台送拍人及参与该拍品竞拍的有效竞拍人';
		set_websms2($message,'',$data['mid'],custom_url('jy_jdpm/member.payment_order//orderid='.$orderid,true),$pid);
		$msg =array('pname'=>$data['pname']);
		set_sms2($member['mobile'],$msg,5,$data['mid']);
return true;